package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.service.OrderService;
import com.railway.service.impl.OrderServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class OrderStateServlet
 */
/**查询订单状态
 * @author 33676
 *
 */
@WebServlet("/OrderStateServlet.do")
public class OrderStateServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("Utf-8");
		int user_id = 0;
		String opcode ="";
		
		if(request.getParameter("user_id") != null && !"".equals(request.getParameter("user_id"))) {
			user_id = Integer.parseInt(request.getParameter("user_id"));
		}
		
		if(request.getParameter("opcode") != null && !"".equals(request.getParameter("opcode"))) {
			opcode = request.getParameter("opcode");
			OrderService os = new OrderServiceImpl();
			
			if("1".equals(opcode)) {
				JSONUtil.responJSOn(response, os.selectOrderUnpaidByUserId(user_id));
			}else if("2".equals(opcode)) {
				JSONUtil.responJSOn(response, os.selectOrderUntravelByUserId(user_id));
			}else if("3".equals(opcode)) {
				JSONUtil.responJSOn(response, os.selectOrderAllByUserId(user_id));
			}else if("4".equals(opcode)) {//可改签
				JSONUtil.responJSOn(response, os.selectOrderticketchangingByUserId(user_id));
			}else if("5".equals(opcode)) {//可退票
				JSONUtil.responJSOn(response, os.selectOrderRefundByUserId(user_id));
			}
		}
		
	}

}
